package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.dubbo.api.db.OptionsApi;
import com.tanhua.dubbo.api.mapper.OptionsMapper;
import com.tanhua.model.db.Options;
import com.tanhua.model.db.Questions;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 选项持久层实现类
 */
@DubboService
public class OptionsApiImpl implements OptionsApi {
    @Autowired
    private OptionsMapper optionsMapper;
    /**
     * 根据问题Id查询选项列表
     */
    @Override
    public List<Options> findOptionsByQuId(String questionsId) {
        QueryWrapper<Options> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("question_id",questionsId);
        return optionsMapper.selectList(queryWrapper);
    }
    /**
     * 获取选项分数
     * @param optionId
     * @return
     */
    @Override
    public Integer findScore(String optionId) {
        QueryWrapper<Options> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("options_id",optionId);
        Options options = optionsMapper.selectOne(queryWrapper);
        return options.getScore();

    }
}
